package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.Category;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.CategoryBrandService;
import com.spzx.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {

    @Autowired
    private CategoryBrandService categoryBrandService;
    @GetMapping("/list")
    public TableDataInfo PageCategoryBrand(){
    startPage();
        List<CategoryBrand> list = categoryBrandService.getPageCategoryBrand();
        return getDataTable(list);
    }
    @PostMapping
    public AjaxResult save(@RequestBody CategoryBrand categoryBrand){
        categoryBrand.setCreateBy(SecurityUtils.getUsername());
        categoryBrandService.saveCategoryBrand(categoryBrand);
        return AjaxResult.success();
    }
    @DeleteMapping("/{id}")
    public AjaxResult deleteCategoryBrand(@PathVariable Long id){
        categoryBrandService.removeById(id);
        return AjaxResult.success();
    }
    @GetMapping("/brandList/{brandId}")
    public AjaxResult getcategoryBrandByBrandId(@PathVariable(name ="brandId") Long brandId){
        List<Brand> categoryBrand = categoryBrandService.getcategoryBrandByBrandId(brandId);
        return AjaxResult.success(categoryBrand);
    }

}
